package com.admin.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pervasive.container.GameContainer;

public class ControllerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private RequestDispatcher requestDispatcher;

    /**
     * Default constructor. 
     */
    public ControllerServlet() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    /**
     * This is a Overridden method to handle HTTP GET Requests from client
     */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		GameContainer gameContainer = GameContainer.getGameContainerInstance();
		
		try
		{
			//Calling the Business Logic and packing the Response up.
			request.setAttribute("Results", gameContainer.getUserData());
	        requestDispatcher = request.getRequestDispatcher("results.jsp");
	        requestDispatcher.forward(request, response);
		}catch (Exception e) {
			// TODO: handle exception
			request.setAttribute("Error", e);
	        requestDispatcher = request.getRequestDispatcher("error.jsp");
	        requestDispatcher.forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	/**
	 * This is a Overridden method to handle HTTP POST Requests from client
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
GameContainer gameContainer = GameContainer.getGameContainerInstance();
		
		try
		{
			//Calling the Business Logic and packing the Response up.
			request.setAttribute("Results", gameContainer.getUserData());
	        requestDispatcher = request.getRequestDispatcher("results.jsp");
	        requestDispatcher.forward(request, response);
		}catch (Exception e) {
			// TODO: handle exception
			request.setAttribute("Error", e);
	        requestDispatcher = request.getRequestDispatcher("error.jsp");
	        requestDispatcher.forward(request, response);
		}
	}
	
}
